<?php
class Business_GmapLocation{
	/**
	 * 
	 * @return Array | Zend_Exception
	 */

	
	public static function getAllIds($ids){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_getGmapLocationByRealIds(:p_ids)');
			$stmt->bindValue('p_ids',$ids);
			$stmt->execute();
			$result = $stmt->fetchAll();			
			return $result;
		} catch (Zend_Exception $e) {
			return $e->getMessage();
		}
	}
	
	/**
	 * 
	 * @param $params['key'] = CustomerID,CustomerName | $params['value'] = 1, Name
	 * @return Array
	 */
	public static function get($params){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_getGmapLocationBy'.$params['key'].'(:s_'.$params['key'].')');
			$stmt->bindValue('s_'.$params['key'],$params['value']);
			$stmt->execute();
			$result = $stmt->fetchAll();
				unset($stmt);
				return $result;
			} catch (Zend_Exception $e) {
			return array();
		}
	}
	

	public static function create($params){
		try {
			
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_insertGmapLocation(:s_RealId,
:s_x
,:s_y)');
			$stmt->bindValue('s_RealId',$params['RealId']);
			$stmt->bindValue('s_x',$params['xcoor']);
			$stmt->bindValue('s_y',$params['ycoor']);
			$stmt->execute();
			$result = $stmt->rowCount();
			
			unset($stmt);
			
			return $result;
		} catch (Zend_Exception $e) {
			return 0;
		}
	}
	/**
	 * 
	 * @param unknown_type $params
	 * @return number
	 */
	public static function update($params){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_updateGmapLocation(:s_RealId,:s_x,
:s_y)');
			$stmt->bindValue('s_RealId',$params['RealId']);
			$stmt->bindValue('s_x',$params['xcoor']);
			$stmt->bindValue('s_y',$params['ycoor']);
			$stmt->execute();			
			
			$result = $stmt->rowCount();
			
			unset($stmt);
			
			return $result;
		} catch (Zend_Exception $e) {
			return 0;
		}
	}
	
	public static function delete($ids){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare("CALL sp_deleteGmapLocatio(:s_RealId)");
			$stmt->bindValue('s_RealId',$ids);
			$stmt->execute();
			return $stmt->rowCount();
		} catch (Zend_Exception $e) {
			return $e->getMessage();
		}
	}
}